package com.jsurf;

import java.io.Serializable;

public class InterestPoint implements Serializable{
	private static final long serialVersionUID = 1;

	// Interpolated X-coordinate.
	private float x;

	// Interpolated Y-coordinate.
	private float y;

	// Detected scale.
	private float scale;

	// Orientation measured anti-clockwise from +ve x-axis. The default is 0 (i.e. upright SURF).
	private float orientation;

	// Sign of hessian traces (laplacian sign).
	private int laplacianSign;

	// Vector of descriptor components.
	private float[] descriptor;

	// Point motion (can be used for frame to frame motion analysis).
	private float dx, dy;
	
	private int clusterIndex;

	// kd-Tree
	public final int DESC_SIZE = 64;
	public Object featureData;
	public InterestPoint fwdMatch;

	public InterestPoint(float x, float y) {
		this.x = x;
		this.y = y;
		descriptor = new float[64];
	}

	public InterestPoint(float x, float y, float scale, int laplacian) {
		this.x = x;
		this.y = y;
		this.scale = scale;
		this.laplacianSign = laplacian;
	}

	// Returns the squared distance between two vectors
	public static float descriptorSquaredDistance(InterestPoint f1, InterestPoint f2) {
		float diff, dsq = 0;
		float desc1[], desc2[];
		int i, d;

		d = f1.DESC_SIZE;
//		if(f2.DESC_SIZE != d) {
//			return Float.MAX_VALUE;
//		}
		desc1 = f1.descriptor;
		desc2 = f2.descriptor;

		for(i = 0; i < d; i++) {
			diff = desc1[i] - desc2[i];
			dsq += diff * diff;
		}
		return dsq;
	}
	
	public float getX() {
		return x;
	}

	public float getY() {
		return y;
	}

	public float getScale() {
		return scale;
	}

	public float getOrientation() {
		return orientation;
	}

	public void setOrientation(float orientation) {
		this.orientation = orientation;
	}

	public int getLaplacianSign() {
		return laplacianSign;
	}

	public float[] getDescriptor() {
		return descriptor;
	}
	
	public void setDescriptor(float[] descriptor) {
		this.descriptor = descriptor;
	}

	public float getDx() {
		return dx;
	}

	public void setDx(float dx) {
		this.dx = dx;
	}

	public float getDy() {
		return dy;
	}

	public void setDy(float dy) {
		this.dy = dy;
	}

	public int getClusterIndex() {
		return clusterIndex;
	}

	public void setClusterIndex(int clusterIndex) {
		this.clusterIndex = clusterIndex;
	}
}
